
import 'package:flutter/material.dart';
import 'package:nft_shop/my/page/write/review_list_page.dart';
import 'package:nft_shop/res/global.dart';
import 'package:nft_shop/widgets/custom_underline_tabIndicator.dart';
import 'package:nft_shop/widgets/my_app_bar.dart';

class ReviewPage extends StatefulWidget {
  const ReviewPage({Key? key}) : super(key: key);

  @override
  _ReviewPageState createState() => _ReviewPageState();
}

class _ReviewPageState extends State<ReviewPage> with TickerProviderStateMixin{
  TabController? _tabController;
  final PageController _pageController = PageController(initialPage: 0);

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _tabController = TabController(vsync: this, length: 4);
  }

  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
    _tabController?.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: MyAppBar(
        centerTitle: "审核",
      ),
      body: Column(
        children: [
          _topWidget(),
          Expanded(
              child: PageView.builder(
                key: const Key('pageView'),
                itemCount: 4,
                onPageChanged: _onPageChange,
                controller: _pageController,
                itemBuilder: (_, int index) {
                  return ReviewListPage(index: index,);
                },
              ))
        ],
      ),
    );
  }



  //选项卡
  Widget _topWidget(){
    return Container(
      child: TabBar(
        onTap: (index) {
          if (!mounted) {
            return;
          }
          _pageController.jumpToPage(index);
        },
        labelPadding: EdgeInsets.zero,
        controller: _tabController,
        labelStyle: TextStyle(fontSize: 14,fontFamily: Global.mySemiboldFont,),
        unselectedLabelStyle:TextStyle(fontSize: 14,),
        indicatorSize: TabBarIndicatorSize.label,
        unselectedLabelColor: Global.kTheme.textPrimary0,
        labelColor: Global.kTheme.textPrimary0,
        indicatorPadding: EdgeInsets.only(bottom: 4,),
        indicator: CustomUnderlineTabIndicator(borderSide: BorderSide(color: Global.kTheme.textPrimary4,width: 4,)),
        tabs: const <Widget>[
          Tab(text: "全部",),
          Tab(text: "审核中",),
          Tab(text: "审核失败",),
          Tab(text: "审核成功",),
        ],
      ),
    );
  }
  //切换页面
  void _onPageChange(int index) {
    _tabController?.animateTo(index);
  }
}
